<template>
  <van-form @submit="edit">
    <h2>修改服务器信息</h2>
    <van-field
        v-model="ip"
        name="服务器IP"
        label="服务器IP"
        placeholder="服务器IP"
        :rules="[{ required: true, message: '请填写服务器IP' }]"
    />
    <van-field
        v-model="yhm"
        name="服务器用户名"
        label="服务器用户名"
        placeholder="服务器用户名"
        :rules="[{ required: true, message: '请填写用户名' }]"
    />
    <van-field
        v-model="mm"
        name="服务器密码"
        label="服务器密码"
        placeholder="服务器密码"
        :rules="[{ required: true, message: '请填写密码' }]"
    />
    <van-field
        v-model="dqsj"
        name="设备时间"
        label="设备时间"
        placeholder="设备时间"
        :rules="[{ required: true, message: '请填写设备时间' }]"
    />
    <van-field name="radio" label="服务商">
      <template #input>
        <van-radio-group v-model="fws" direction="horizontal">
          <van-radio name="阿里云">阿里云</van-radio>
          <van-radio name="腾讯云">腾讯云</van-radio>
        </van-radio-group>
      </template>
    </van-field>
    <van-field
        v-model="dy"
        name="地域"
        label="地域"
        placeholder="地域"
        :rules="[{ required: true, message: '请填写地域' }]"
    />
    <van-field
        v-model="yyz"
        name="拥有者"
        label="拥有者"
        placeholder="拥有者"
        :rules="[{ required: true, message: '请填写拥有者' }]"
    />
    <van-field
        v-model="bz"
        name="备注"
        label="备注"
        placeholder="备注"
        :rules="[{ required: false, message: '请填写备注' }]"
    />
    <div style="margin: 16px;" class="text-center visible-lg visible-md">
      <van-button round type="info" native-type="submit" style="width: 30%;">修改</van-button>
    </div>
    <div style="margin: 16px;" class="text-center visible-sm visible-xs">
      <van-button round type="info" native-type="submit" style="width: 70%;">修改</van-button>
    </div>
  </van-form>
</template>

<script>
import qs from "qs"
import {setServer} from "../../utils/api";
export default {
  name: "ServerEdit",
  created() {
    let { bz,dqsj,dy,fws,id,ip,mm,yhm,yyz } =this.$route.params;
    this.bz=bz;
    this.dqsj=dqsj;
    this.dy=dy;
    this.fws=fws;
    this.id=id;
    this.ip=ip;
    this.mm=mm;
    this.yhm=yhm;
    this.yyz=yyz;
  },
  data(){
    return {
      id:'',
      ip:'',
      yhm:'',
      mm:'',
      dqsj:'',
      fws:'',
      dy:'',
      yyz:'',
      bz:''
    }
  },
  methods:{
    edit(){
      this.$dialog.confirm({
        message: '您确定要修改了吗？',
      }).then(() => {
        setServer(qs.stringify(
            {id:this.id,ip:this.ip,yhm:this.yhm,mm:this.mm,dqsj:new Date(this.dqsj).getTime(),fws:this.fws,dy:this.dy,yyz:this.yyz,bz:this.bz})
        ).then(respose=>{
          if(respose.status===200){
            this.$toast.success("修改成功");
            this.$router.go(-1);
          }else{
            this.$toast.fail("修改失败")
          }
        }).catch(error=>{
          console.log(error);
        })
      }).catch(() => {})
    }
  }
}
</script>

<style scoped>

</style>